//
//  WCAFailListCell.m
//  WeChatBuniess
//
//  Created by Guo Rui on 2017/12/26.
//  Copyright © 2017年 GR Harry. All rights reserved.
//

#import "WCAFailListCell.h"
#import "UIImage+Ex.h"

@interface WCAFailListCell()
@property (strong, nonatomic) UILabel *weidLabel;
@property (strong, nonatomic) UILabel *nickLabel;
@property (strong, nonatomic) UIButton *retryButton;
@end

@implementation WCAFailListCell

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    CGFloat x, y, w, h;
    CGFloat width = CGRectGetWidth(self.contentView.frame);
    CGFloat height = CGRectGetHeight(self.contentView.frame);
    
    {
        // retryButton
        w = 120.f;
        x = width - 30.f - w;
        h = 40.f;
        y = (height - h) / 2.f;
        self.retryButton.frame = CGRectMake(x, y, w, h);
    }
    
    {
        // weidLabel
        x = 40.f;
        y = 10.f;
        w = width - CGRectGetMinX(self.retryButton.frame) - 20.f;
        h = 30.f;
        self.weidLabel.frame = CGRectMake(x, y, w, h);
    }
    
    {
        // nickLabel
        x = 40.f;
        h = 30.f;
        y = height - 10.f - h;
        w = 300.f;
        self.nickLabel.frame = CGRectMake(x, y, w, h);
    }
}

#pragma mark - Public
- (void)retryEnable
{
    self.retryButton.enabled = YES;
}

- (void)retryDisable
{
    self.retryButton.enabled = NO;
}

- (void)setC:(WCACotact *)c
{
    _c = c;
    
    self.weidLabel.text = c.contact.m_nsUsrName;
    self.nickLabel.text = [NSString stringWithFormat:@"昵称 :%@", c.contact.m_nsNickName];
}

#pragma mark - Actions
- (void)retryDidClick
{
    [self retryDisable];
    if (self.retryBlock) {
        self.retryBlock();
    }
    NSLog(@"%s", __func__);
}

#pragma mark - Getter
- (UILabel *)weidLabel
{
    if (!_weidLabel) {
        _weidLabel = [[UILabel alloc] init];
        _weidLabel.textColor = [UIColor blackColor];
        _weidLabel.font = [UIFont systemFontOfSize:23];
        [self.contentView addSubview:_weidLabel];
    }
    return _weidLabel;
}

- (UILabel *)nickLabel
{
    if (!_nickLabel) {
        _nickLabel = [[UILabel alloc] init];
        _nickLabel.textColor = [UIColor lightGrayColor];
        _nickLabel.font = [UIFont systemFontOfSize:19];
        [self.contentView addSubview:_nickLabel];
    }
    return _nickLabel;
}

- (UIButton *)retryButton
{
    if (!_retryButton) {
        _retryButton = [UIButton buttonWithType:UIButtonTypeCustom];
        
        [_retryButton setTitle:@"重新发送" forState:UIControlStateNormal];
        [_retryButton setTitle:@"正在发送" forState:UIControlStateDisabled];
        [_retryButton setBackgroundImage:[UIImage tf_imageWithColor:[UIColor colorWithRed:0.11 green:0.62 blue:0.94 alpha:1.00]] forState:UIControlStateNormal];
        [_retryButton setBackgroundImage:[UIImage tf_imageWithColor:[UIColor lightGrayColor]] forState:UIControlStateDisabled];
        
        _retryButton.titleLabel.font = [UIFont systemFontOfSize:20];
        
        _retryButton.layer.cornerRadius = 5.f;
        _retryButton.layer.masksToBounds = YES;
        
        [_retryButton addTarget:self action:@selector(retryDidClick) forControlEvents:UIControlEventTouchUpInside];
        
        [self.contentView addSubview:_retryButton];
    }
    return _retryButton;
}

@end
